<!-- HTML header for doxygen 1.8.3.1-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.3.1"/>
<title>AngelScript: Helper functions</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="test/javascript" src="touch.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="aslogo_small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">AngelScript
   </div>
  </td>
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.3.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('doc_addon_helpers.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Helper functions </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>Path:</b> /sdk/add_on/scripthelper/</p>
<p>These helper functions simplify the implemention of common tasks. They can be used as is or can serve as the starting point for your own framework.</p>
<h1><a class="anchor" id="doc_addon_helpers_1"></a>
Public C++ interface</h1>
<div class="fragment"><div class="line"><span class="comment">// Compare relation between two objects of the same type.</span></div>
<div class="line"><span class="comment">// Uses the object&#39;s opCmp method to perform the comparison.</span></div>
<div class="line"><span class="comment">// Returns a negative value if the comparison couldn&#39;t be performed.</span></div>
<div class="line"><span class="keywordtype">int</span> CompareRelation(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine, <span class="keywordtype">void</span> *leftObj, <span class="keywordtype">void</span> *rightObj, <span class="keywordtype">int</span> typeId, <span class="keywordtype">int</span> &amp;result);</div>
<div class="line"></div>
<div class="line"><span class="comment">// Compare equality between two objects of the same type.</span></div>
<div class="line"><span class="comment">// Uses the object&#39;s opEquals method to perform the comparison, or if that doesn&#39;t exist the opCmp method.</span></div>
<div class="line"><span class="comment">// Returns a negative value if the comparison couldn&#39;t be performed.</span></div>
<div class="line"><span class="keywordtype">int</span> CompareEquality(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine, <span class="keywordtype">void</span> *leftObj, <span class="keywordtype">void</span> *rightObj, <span class="keywordtype">int</span> typeId, <span class="keywordtype">bool</span> &amp;result);</div>
<div class="line"></div>
<div class="line"><span class="comment">// Compile and execute simple statements.</span></div>
<div class="line"><span class="comment">// The module is optional. If given the statements can access the entities compiled in the module.</span></div>
<div class="line"><span class="comment">// The caller can optionally provide its own context, for example if a context should be reused.</span></div>
<div class="line"><span class="keywordtype">int</span> ExecuteString(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine, <span class="keyword">const</span> <span class="keywordtype">char</span> *code, <a class="code" href="classas_i_script_module.html" title="The interface to the script modules.">asIScriptModule</a> *mod = 0, <a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx = 0);</div>
<div class="line"></div>
<div class="line"><span class="comment">// Compile and execute simple statements with option of return value.</span></div>
<div class="line"><span class="comment">// The module is optional. If given the statements can access the entitites compiled in the module.</span></div>
<div class="line"><span class="comment">// The caller can optionally provide its own context, for example if a context should be reused.</span></div>
<div class="line"><span class="keywordtype">int</span> ExecuteString(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine, <span class="keyword">const</span> <span class="keywordtype">char</span> *code, <span class="keywordtype">void</span> *ret, <span class="keywordtype">int</span> retTypeId, <a class="code" href="classas_i_script_module.html" title="The interface to the script modules.">asIScriptModule</a> *mod = 0, <a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx = 0);</div>
<div class="line"></div>
<div class="line"><span class="comment">// Format the details of the script exception into a human readable text.</span></div>
<div class="line"><span class="comment">// Whenever the asIScriptContext::Execute method returns asEXECUTION_EXCEPTION, the application </span></div>
<div class="line"><span class="comment">// can call this function to get more information about that exception in a human readable form.</span></div>
<div class="line"><span class="comment">// The information obtained includes the current function, the script source section, </span></div>
<div class="line"><span class="comment">// program position in the source section, and the exception description itself.</span></div>
<div class="line">std::string GetExceptionInfo(<a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx, <span class="keywordtype">bool</span> showStack = <span class="keyword">false</span>);</div>
<div class="line"></div>
<div class="line"><span class="comment">// Write registered application interface to file.</span></div>
<div class="line"><span class="comment">// This function creates a file with the configuration for the offline compiler, asbuild, in the samples.</span></div>
<div class="line"><span class="comment">// If you wish to use the offline compiler you should call this function from you application after the </span></div>
<div class="line"><span class="comment">// application interface has been fully registered. This way you will not have to create the configuration</span></div>
<div class="line"><span class="comment">// file manually.</span></div>
<div class="line"><span class="keywordtype">int</span> WriteConfigToFile(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine, <span class="keyword">const</span> <span class="keywordtype">char</span> *filename);</div>
<div class="line"></div>
<div class="line"><span class="comment">// Write the registered application interface to a text stream. </span></div>
<div class="line"><span class="keywordtype">int</span> WriteConfigToStream(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine, std::ostream &amp;strm); </div>
<div class="line"></div>
<div class="line"><span class="comment">// Loads an interface from a text stream and configures the engine with it. This will not </span></div>
<div class="line"><span class="comment">// set the correct function pointers, so it is not possible to use this engine to execute</span></div>
<div class="line"><span class="comment">// scripts, but it can be used to compile scripts and save the byte code.</span></div>
<div class="line"><span class="keywordtype">int</span> ConfigEngineFromStream(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine, std::istream &amp;strm, <span class="keyword">const</span> <span class="keywordtype">char</span> *nameOfStream = <span class="stringliteral">&quot;config&quot;</span>);</div>
</div><!-- fragment --><h1><a class="anchor" id="doc_addon_helpers_2"></a>
Example</h1>
<p>To compare two script objects the application can execute the following code:</p>
<div class="fragment"><div class="line"><span class="keywordtype">void</span> Compare(<a class="code" href="classas_i_script_object.html" title="The interface for an instance of a script object.">asIScriptObject</a> *a, <a class="code" href="classas_i_script_object.html" title="The interface for an instance of a script object.">asIScriptObject</a> *b)</div>
<div class="line">{</div>
<div class="line">  <a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine = a-&gt;<a class="code" href="classas_i_script_object.html#a5dda2d380ae1580e15ddf9d95893c57a" title="Return the script engine.">GetEngine</a>();</div>
<div class="line">  <span class="keywordtype">int</span> typeId = a-&gt;<a class="code" href="classas_i_script_object.html#a19c5ab9d8adb0f921bf0b6474d97f468" title="Returns the type id of the object.">GetTypeId</a>();</div>
<div class="line"></div>
<div class="line">  <span class="keywordtype">int</span> cmp;</div>
<div class="line">  <span class="keywordtype">int</span> r = CompareRelation(engine, a, b, typeId, cmp);</div>
<div class="line">  <span class="keywordflow">if</span>( r &lt; 0 )</div>
<div class="line">  {</div>
<div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;The relation between a and b cannot be established b&quot;</span> &lt;&lt; endl;</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">else</span></div>
<div class="line">  {</div>
<div class="line">    <span class="keywordflow">if</span>( cmp &lt; 0 )</div>
<div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;a is smaller than b&quot;</span> &lt;&lt; endl;</div>
<div class="line">    <span class="keywordflow">else</span> <span class="keywordflow">if</span>( cmp == 0 )</div>
<div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;a is equal to b&quot;</span> &lt;&lt; endl;</div>
<div class="line">    <span class="keywordflow">else</span></div>
<div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;a is greater than b&quot;</span> &lt;&lt; endl;</div>
<div class="line">  }</div>
<div class="line">}</div>
</div><!-- fragment --> </div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Sun Dec 18 2016 12:35:27 for AngelScript by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.3.1 </li>
  </ul>
</div>
</body>
</html>
